<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.14.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>DM-CtrlH7-BF-DevProgram: HT04</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="50x5.png"/></td>
  <td id="projectalign">
   <div id="projectname">DM-CtrlH7-BF-DevProgram<span id="projectnumber">&#160;beta 0.1</span>
   </div>
   <div id="projectbrief">C.ONE Studio Damiao Development Board Framework</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.14.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search/",'.html');
</script>
<script type="text/javascript">
$(function() { codefold.init(); });
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search',true);
  $(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(function(){initNavTree('md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2motor_2_h_tmotor_2_h_t04.html','',''); });
</script>
<div id="container">
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div><div class="header">
  <div class="headertitle"><div class="title">HT04 </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><ul>
<li>在通过串口设置电机的时候，注意发送指令不要追加回车<br  />
，否则电机端不响应。可以使用sscom，其会将你的按键直接当作ascii字符发送出去。</li>
<li><b>此电机的CAN线序和RoboMaster开发板相反，注意单独制作CAN线</b></li>
<li>电机控制和反馈报文： <img src="%E6%8E%A7%E5%88%B6%E6%8A%A5%E6%96%87.png" alt="控制报文" class="inline"/></li>
</ul>
<p>注意，我们的代码实现不使用其电调协议的位置PD算法；自行实现了三环，并在最后给出电流参考值，发送给电调。因此command packed structure中的**pos cmd &amp; vel cmd &amp; Kp &amp; Kd均为零**。报文均为小端，**低位在前**。</p>
<p>请注意发送和反馈数据的**单位**。</p>
<blockquote class="doxtable">
<p><strike>HT的电机协议做的真不行，纯纯直接抄mit还抄不明白，之后全部换成LK！</strike> </p>
</blockquote>
<p>另一种上电时校准编码器的方法:</p>
<div class="fragment"><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> HTMotorDecode(CANInstance *motor_can)</div>
<div class="line">{</div>
<div class="line">    uint16_t tmp; <span class="comment">// 用于暂存解析值,稍后转换成float数据,避免多次创建临时变量</span></div>
<div class="line">    uint8_t *rxbuff = motor_can-&gt;rx_buff;</div>
<div class="line">    <a class="code hl_struct" href="struct_h_t_motor___measure__t.html">HTMotor_Measure_t</a> *measure = &amp;((<a class="code hl_struct" href="struct_h_t_motor_instance.html">HTMotorInstance</a> *)motor_can-&gt;id)-&gt;measure; <span class="comment">// 将can实例中保存的id转换成电机实例的指针</span></div>
<div class="line"> </div>
<div class="line">    measure-&gt;last_angle = measure-&gt;total_angle;</div>
<div class="line">    tmp = (uint16_t)((rxbuff[1] &lt;&lt; 8) | rxbuff[2]);</div>
<div class="line">    measure-&gt;total_angle = uint_to_float(tmp, P_MIN, P_MAX, 16) - measure-&gt;angle_bias;</div>
<div class="line"> </div>
<div class="line">    tmp = (uint16_t)(rxbuff[3] &lt;&lt; 4) | (rxbuff[4] &gt;&gt; 4);</div>
<div class="line">    measure-&gt;speed_rads = AverageFilter((uint_to_float(tmp, V_MIN, V_MAX, 12) - HT_SPEED_BIAS), measure-&gt;speed_buff, SPEED_BUFFER_SIZE);</div>
<div class="line"> </div>
<div class="line">    tmp = (uint16_t)(((rxbuff[4] &amp; 0x0f) &lt;&lt; 8) | rxbuff[5]);</div>
<div class="line">    measure-&gt;real_current = CURRENT_SMOOTH_COEF * uint_to_float(tmp, T_MIN, T_MAX, 12) +</div>
<div class="line">                            (1 - CURRENT_SMOOTH_COEF) * measure-&gt;real_current;</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">if</span> (!measure-&gt;first_feedback_flag) <span class="comment">// 初始化的时候设置偏置</span></div>
<div class="line">    {</div>
<div class="line">        measure-&gt;first_feedback_flag = 1;</div>
<div class="line">        measure-&gt;angle_bias = measure-&gt;total_angle;</div>
<div class="line">        measure-&gt;total_angle = 0;</div>
<div class="line">        measure-&gt;speed_rads = 0;</div>
<div class="line">    }</div>
<div class="line">}</div>
<div class="ttc" id="astruct_h_t_motor___measure__t_html"><div class="ttname"><a href="struct_h_t_motor___measure__t.html">HTMotor_Measure_t</a></div><div class="ttdef"><b>Definition</b> HT04.h:28</div></div>
<div class="ttc" id="astruct_h_t_motor_instance_html"><div class="ttname"><a href="struct_h_t_motor_instance.html">HTMotorInstance</a></div><div class="ttdef"><b>Definition</b> HT04.h:43</div></div>
</div><!-- fragment --><p>第一次收到数据时默认电机处于限位处,将速度和角度都设置为零,记录当前的编码器数据,之后每次收到都减去该值. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
</div><!-- container -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.14.0 </li>
  </ul>
</div>
</body>
</html>
